import requests


class HttpReq:
    @staticmethod
    def get(url, params=None, headers=None):
        return HttpReq.base_req(method="GET", url=url, params=params, headers=headers)

    @staticmethod
    def post(url, params=None, json=None, headers=None, files=None):
        return HttpReq.base_req(method="POST", url=url, params=params, json=json, headers=headers, files=files)

    @staticmethod
    def put(url, params=None, json=None, headers=None):
        return HttpReq.base_req(method="PUT", url=url, params=params, json=json, headers=headers)

    @staticmethod
    def delete(url, params=None, json=None, headers=None):
        return HttpReq.base_req(method="DELETE", url=url, params=params, json=json, headers=headers)

    @staticmethod
    def base_req(method="GET", url=None, params=None, json=None, headers=None, files=None):
        response = requests.request(method=method, url=url, params=params, json=json, headers=headers, files=files)
        if response.status_code != 200 or response.json().get("code") != 1:
            raise Exception(response)
        return response.json().get("data")
